(function($){
	setInterval(function(){
		if($(document).height() > $("#footer").position().top+34){
			$("#sidebar").css("height",($(document).height()-106)+"px");
			$("#footer").css("top",$(document).height()+"px").show();
		}else{
			$('body').height($("#sidebar").height()+106);
		}
	},200);
})(jQuery);

Date.prototype.format = function(format) {  
    /* 
     * eg:format="yyyy-MM-dd hh:mm:ss"; 
     */  
    var o = {  
        "M+" : this.getMonth() + 1, // month  
        "d+" : this.getDate(), // day  
        "h+" : this.getHours(), // hour  
        "m+" : this.getMinutes(), // minute  
        "s+" : this.getSeconds(), // second  
        "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S" : this.getMilliseconds()  
        // millisecond  
    };  
  
    if (/(y+)/.test(format)) {  
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4  
                        - RegExp.$1.length));  
    }  
  
    for (var k in o) {  
        if (new RegExp("(" + k + ")").test(format)) {  
            format = format.replace(RegExp.$1, RegExp.$1.length == 1  
                            ? o[k]  
                            : ("00" + o[k]).substr(("" + o[k]).length));  
        }  
    }  
    return format;  
};

/**
 * Create link. 
 * 
 * @param  string $moduleName 
 * @param  string $methodName 
 * @param  string $vars 
 * @param  string $viewType 
 * @access public
 * @return string
 */
function createLink(moduleName, methodName, vars, viewType)
{
	
    if(!viewType) viewType = config.defaultView;
    if(vars)
    {
        vars = vars.split('&');
        for(i = 0; i < vars.length; i ++) vars[i] = vars[i].split('=');
    }
    if(config.requestType == 'PATH_INFO')
    {
        link = config.webRoot + moduleName + config.requestFix + methodName;
        if(vars)
        {
            if(config.pathType == "full")
            {
                for(i = 0; i < vars.length; i ++) link += config.requestFix + vars[i][0] + config.requestFix + vars[i][1];
            }
            else
            {
                for(i = 0; i < vars.length; i ++) link += config.requestFix + vars[i][1];
            }
        }
        link += '.' + viewType;
    }
    else
    {
        link = config.router + '?' + config.moduleVar + '=' + moduleName + '&' + config.methodVar + '=' + methodName + '&' + config.viewVar + '=' + viewType;
        if(vars) for(i = 0; i < vars.length; i ++) link += '&' + vars[i][0] + '=' + vars[i][1];
    }
    return link;
}

/**
开始搜索页面函数
*/
function startSearch(moduleName, methodName){
	var args=arguments,
	    src=location.href;
	    vars = src.split('?')[1];	
		vars = vars.split('&');	
		
		var return_array=new Object();
		for(var i = 0; i < vars.length; i++) {
			var var_array=vars[i].split('=');
			return_array[var_array[0]]=var_array[1];
		}
		for(var j=2;j<arguments.length;j++){
			return_array[arguments[j]]=encodeURI($("#"+arguments[j]).val());
		}
		
		delete return_array.m;
		delete return_array.f;
		delete return_array.t;//config.viewVar  是这个值，如是配置文件改变，这里相应改变
		var vars_config='';
		for(var k in return_array){
		   vars_config+=k;
		   vars_config+='=';
		   vars_config+=return_array[k]+"&";
		}
		vars_config=vars_config.substr(0,vars_config.length-1);
		//console.log(vars_config);
		//console.log(createLink(moduleName,methodName,vars_config));
		location.href=createLink(moduleName,methodName,vars_config);
	//	console.log(return_array);
    //console.log(arguments);
}

/**
 * Switch language.
 * 
 * @param  object $switcher 
 * @access public
 * @return void
 */
function switchLang(switcher)
{
    $.cookie('lang', $(switcher).data('lang'));
    location.href = location.href;
}

function tipInfo(title,time){
  if(!time) var time=2500;
  $.jGrowl(title, {life: time});
}

/*提示等待信息*/
function wait_info(title){
	 return $.dialog({
			width:300,
			lock:true,
			title:title,
			content:"<div style='text-align:center'><img src='theme/default/img/ajax_loader.gif'/></div>",
			btn: {                      
			  ok: {                     
				val: '关闭',            
				type: 'green',  
				click: function(btn) {
					
				}
			  }
			}
		  });
}
